<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="设备编号" prop="deviceCode">
        <el-input v-model="queryParams.deviceCode" placeholder="请输入设备编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="设备名称" prop="deviceName">
        <el-input v-model="queryParams.deviceName" placeholder="请输入设备名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="管理人" prop="managerUserId">
        <UserDialog v-model="queryParams.managerUserId"></UserDialog>
      </el-form-item>
      <el-form-item label="检验部门" prop="deptId">
        <el-cascader :props="{ value: 'id', checkStrictly: true }" :show-all-levels="false" placeholder="请选择部门"
          v-model="queryParams.deptId" :options="deptOptions"></el-cascader>
      </el-form-item>
      <el-form-item label="日期">
        <el-date-picker v-model="dateRange" value-format="yyyy-MM-dd HH:mm:ss" type="daterange" range-separator="-"
          start-placeholder="开始日期" end-placeholder="结束日期" style="width: 240px"
          :default-time="['00:00:00', '23:59:59']"></el-date-picker>
      </el-form-item>
      <el-form-item label="位置" prop="site">
        <el-select filterable v-model="queryParams.site" placeholder="请选择位置" clearable :style="{ width: '100%' }">
          <el-option v-for="dict in dict.type.sys_site_list" :key="dict.value" :label="dict.label" :value="dict.label" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:user:add']"
          >新增</el-button
        >
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['equipment:register:register']"
          >登记</el-button
        >
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:user:remove']"
          >删除</el-button
        >
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['equipment:register:export']">导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="printBox"
          v-hasPermi="['equipment:register:print']">打印</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table @selection-change="handleSelectionChange" fit v-loading="loading" border :data="dataList">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column width="150" label="设备编号" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <el-link v-if="scope.row.deviceCode" @click="handleDetail(scope.row)" type="primary">{{ scope.row.isComplete !=
            1 ? "--" : scope.row.deviceCode }}</el-link>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column width="150" label="设备名称" prop="deviceName" />
      <el-table-column show-overflow-tooltip label="设备状态" width="150">
        <template slot-scope="scope">
          <el-tag size="mini">{{ scope.row.statusName }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="待办业务" min-width="250">
        <template slot-scope="scope">
          <el-tag @click="handleBus(scope.row)" style="cursor: pointer" size="mini" v-if="scope.row.busStatus != -1">{{
            scope.row.busStatusName }}</el-tag>
          <span v-else>-- </span>
        </template>
      </el-table-column>
      <el-table-column width="100" label="是否已登记" align="center">
        <template slot-scope="scope">
          <el-link v-if="scope.row.isComplete == 1" type="success" :underline="false">是</el-link>
          <el-link v-else-if="scope.row.isComplete == 0" type="danger" :underline="false">否</el-link>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column width="120" label="审核状态" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <el-link v-if="scope.row.managerAudit == 1" type="primary">审核通过</el-link>
          <el-link v-else-if="scope.row.managerAudit == 2" type="danger">审核驳回</el-link>
          <span v-else>未审核</span>
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" width="150" label="生产厂家" prop="manufacturer" />
      <el-table-column :show-overflow-tooltip="true" width="120" label="规格型号" prop="spec" />
      <el-table-column :show-overflow-tooltip="true" width="120" label="测量范围 " prop="checkScope" />
      <el-table-column :show-overflow-tooltip="true" width="120" label="所属部门 " prop="deptName" />
      <el-table-column :show-overflow-tooltip="true" width="120" label="位置" prop="site" />
      <el-table-column :show-overflow-tooltip="true" width="120" label="管理人" prop="managerUserName" />
      <el-table-column show-overflow-tooltip width="150" label="校准/计量检定有效期" prop="checkPeriod">
        <template slot-scope="scope">
          {{ scope.row.checkPeriod }}个月
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="300" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" v-hasPermi="['equipment:register:info']"
            @click="handleDetail(scope.row)">详情</el-button>
          <!-- {{ scope.row.isComplete }} -->
          <el-button size="mini" type="text" v-print="print" v-hasPermi="['equipment:register:QR']"
            @click="handleprintArea(scope.row)">小程序查看</el-button>
          <el-button v-if="scope.row.isComplete == 1" size="mini" type="text"
            v-hasPermi="['equipment:register:history:record']" @click="handleRecord(scope.row)">设备流转记录</el-button>
          <el-button  v-if="scope.row.isComplete != 1" size="mini" type="text" icon="el-icon-edit"
            @click="handleUpdate(scope.row)" v-hasPermi="['equipment:register:registration']">登记</el-button>
          <!-- <el-button v-if="scope.row.managerAudit == 2" size="mini" type="text" icon="el-icon-edit"
            @click="handleUpdate2(scope.row)" v-hasPermi="['equipment:register:register']">修改</el-button> -->
          <el-button v-if="scope.row.isComplete == 1" size="mini" type="text" icon="el-icon-edit"
            @click="handleUpdate2(scope.row, true)" v-hasPermi="['equipment:register:edit:manger']">管理员修改</el-button>
          <el-button v-show="(scope.row.managerAudit == 0) && scope.row.isComplete == 1" size="mini" type="text"
            @click="handleAudit(scope.row)" v-hasPermi="['equipment:register:aduit']">审核</el-button>
          <el-button size="mini" type="text" @click="handleUpload(scope.row)"
            v-hasPermi="['equipment:check:upload']">上传</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['company:news:remove']"
            >删除</el-button
          > -->
        </template>
      </el-table-column>
    </el-table>
    <el-dialog title="审核" :visible.sync="openAudit" width="700px" append-to-body>
      <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
        <el-form-item label="审核结果" prop="managerAudit">
          <el-radio-group v-model="formData.managerAudit">
            <el-radio label="1">审核通过</el-radio>
            <el-radio label="2">审核不通过</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="审核原因" v-if="formData.managerAudit == 2" prop="managerCause">
          <el-input v-model="formData.managerCause" placeholder="请输入审核原因" clearable :style="{ width: '100%' }"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="openAudit = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 打印模板位置 -->
    <PrintBox :pageNum="queryParams.pageNum" :total="total" :printRow="printList" :isVertical="false" :isPageSize="false"
      id="printBox">
      <template slot="title" slot-scope="scope">
        <div style="margin-bottom: 40px">设备情况登记表 STET/B/20-1</div>
      </template>
      <template slot-scope="scope">
        <!-- 表格  class  table-page  必须-->
        <table style="border-collapse: collapse; table-layout: fixed; width: 100%" border="1" cellspacing="0"
          class="table-page" :isVertical="false">
          <tr style="height: 16mm">
            <td>设备名称</td>
            <td colspan="2">{{ scope.item.deviceName }}</td>
            <td>设备编号</td>
            <td>{{ scope.item.deviceCode }}</td>
            <td colspan="2" rowspan="4">
              <img style="width: 280px; height: 250px;object-fit: cover" :src="$VUE_APP_IMG_API + scope.item.image"></img>
            </td>
          </tr>
          <tr style="height: 16mm">
            <td>规格编号</td>
            <td colspan="2">{{ scope.item.spec }}</td>
            <td>出厂编号</td>
            <td>{{ scope.item.code }}</td>
          </tr>
          <tr style="height: 16mm">
            <td>制造厂商</td>
            <td colspan="2">
              {{ scope.item.manufacturer }}
              <!-- {{
                checkDict(
                  dict.type.sys_manufacturer_list,
                  scope.item.manufacturer
                )
              }} -->
            </td>
            <td>出厂日期</td>
            <td>{{ scope.item.factoryDate }}</td>
          </tr>
          <tr style="height: 16mm">
            <td>供应商</td>
            <td colspan="2">{{ scope.item.supplierName }}</td>
            <td>联系方式</td>
            <td>{{ scope.item.phone }}</td>
          </tr>
          <tr style="height: 16mm">
            <td>移交附件</td>
            <td colspan="3">{{ scope.item.turnAttachment || '' }}</td>
            <td>允许操作人员</td>
            <td colspan="2">
              {{ scope.item.operUserName }}
            </td>
          </tr>
          <tr style="height: 16mm">
            <td>设备用途</td>
            <td colspan="3">{{ scope.item.useInfo }}</td>
            <td>管理人</td>
            <td colspan="2">{{ scope.item.managerUserName }}</td>
          </tr>
          <tr style="height: 16mm">
            <td>操作规程</td>
            <td colspan="2">
              <div style="text-align: center;display: flex;align-items: center;">
                <input type="checkbox" :checked="scope.item.operStandard == 0" />有，受控编号{{ scope.item.standardCode }}
              </div>
              <div style="text-align: center;display: flex; align-items: center;">
                <input type="checkbox" :checked="scope.item.operStandard == 1" />无
              </div>
            </td>
            <td>操作视频</td>
            <td>
              <div style="text-align: center;display: flex;
    align-items: center;justify-content: center;">
                <input :checked="scope.item.isVideo == 0" type="checkbox" />有
              </div>
              <div style="text-align: center;display: flex;
    align-items: center;justify-content: center;">
                <input :checked="scope.item.isVideo == 1" type="checkbox" />无
              </div>
            </td>
            <td style="width: 10px">校验/计量检定周期</td>
            <td>{{ scope.item.checkPeriod }}月</td>
          </tr>
          <tr style="height: 16mm">
            <td>维护保养内容</td>
            <td colspan="2">{{ scope.item.careContent }}</td>
            <td>维护保养周期</td>
            <td>{{ scope.item.carePeriod }}月</td>
            <td>溯源方式</td>
            <td>
              {{
                checkDict(dict.type.sys_trace_method, scope.item.traceMethod)
              }}
            </td>
          </tr>
          <tr style="height: 16mm">
            <td>测量范围</td>
            <td colspan="2">{{ scope.item.checkScope }}</td>
            <td>扩展不确定度/最大允差/准确度等级</td>
            <td>{{ scope.item.checkLevel }}</td>
            <td>分度值</td>
            <td>{{ scope.item.scaleValue }}</td>
          </tr>
          <tr style="height: 16mm">
            <td>精度</td>
            <td colspan="2">{{ scope.item.scale }}</td>
            <td>所属部门</td>
            <td>{{ scope.item.deptName }}</td>
            <td>位置</td>
            <td>{{ scope.item.site }}</td>
          </tr>
        </table>
        <!-- 底部信息位置 -->
        <div class="page-bottom" style="page-break-after: always">
          <div class="desc">注：本表格自2023年2月1日起生效</div>
        </div>
      </template>
    </PrintBox>
    <el-dialog :visible.sync="showCode" title="小程序查看" width="300px" append-to-body>

    </el-dialog>
    <!-- 小票打印 -->
    <div id="printArea" class="noprint">
      <table style="border-collapse: collapse; table-layout: fixed; width: 100%;height: 100%;" border="3" cellspacing="0"
        class="table-page" :isVertical="false">
        <!-- 第一行 -->
        <tr>
          <!-- rowspan行高： 2  colspan列高： 2 -->
          <td colspan="8" class="fw tac br" style="border: 2px solid #000;">苏州交通工程试验检测中心有限公司</td>
          <td rowspan="3" colspan="4" style="text-align: center;" class="br"><vue-qr :text="textUrl" :size="100"
              margin="0"></vue-qr></td>
        </tr>

        <tr>
          <td colspan="2" class="fw tac br">设备名称</td>
          <td colspan="6" class="tac br">{{ printItem.deviceName }}</td>

        </tr>
        <tr>
          <td colspan="2" class="fw tac br">设备编号</td>
          <td colspan="6" class="tac br">{{ printItem.deviceCode }}</td>

        </tr>

        <tr>
          <td colspan="2" class="fw tac br">管理人员</td>
          <td colspan="4" class="tac br">{{ printItem.managerUserName }}</td>
          <td colspan="2" class="fw tac br">规格型号</td>
          <td colspan="4" class="tac br">{{ printItem.spec }}</td>
        </tr>
        <tr>
          <td colspan="2" class="fw tac br">出厂编号</td>
          <td colspan="4" class="tac br">{{ printItem.code }}</td>
          <td colspan="2" class="fw tac br">生产厂家</td>
          <td colspan="4" class="tac br">{{ printItem.manufacturer }}</td>
        </tr>
        <tr>
          <td colspan="2" class="fw tac br">购置日期</td>
          <td colspan="4" class="tac br">{{ printItem.buyDate && printItem.buyDate.substr(0, 11) }}</td>
          <td colspan="2" class="fw tac br">所在位置</td>
          <td colspan="4" class="tac br">{{ printItem.site }}</td>
        </tr>
        <!-- 第二行 -->



      </table>
      <!-- <table style="border-collapse: collapse; table-layout: fixed; width: 100%;height: 100%;" border="1" cellspacing="0"
        class="table-page" :isVertical="false">
        <tr style="height: 20%;">
          <td style="white-space: nowrap;width: 70%;" colspan="1" rowspan="10 "> 苏州交通工程试验检测中心有限公司</td>
          <td colspan="3" rowspan="5" style="width: 30%;">
            <vue-qr :text="textUrl" :size="100"></vue-qr>
          </td>
        </tr>
        <tr style="height: 20%;">
          <td style="white-space: nowrap;width: 30%;" colspan="1" rowspan="2">设备名称</td>
          <td colspan="1" rowspan="2" style="width: 4%;">2</td>
        </tr>
        <tr style="height: 20%;">
          <td style="white-space: nowrap" colspan="1" rowspan="2">规格编号</td>
          <td  colspan="1" rowspan="2">3</td>
        </tr>
      </table> -->
    </div>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <el-dialog title="上传附件" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="附件信息（移交附件、期间核查作业指导书）">
          <FileUploadBase v-model="form.oss"></FileUploadBase>
        </el-form-item>
        <el-form-item label="设备图片" prop="image">
          <imageUpload :limit="1" :disabled="$route.query.isInfo || isInfo"
            :fileType="['png', 'jpg', 'jpeg', 'PDF', 'pdf']" v-model="form.image" />
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="titleLog" :visible.sync="openLog" width="700px" append-to-body>
      <el-table v-if="openLog" fit v-loading="loadingLog" :data="dataPayLogList">
        <el-table-column :render-header="lableRender">
          <el-table-column label="所在部门" min-width="150" prop="deptName" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column label="所在位置" min-width="150" prop="site" show-overflow-tooltip>
            <!-- <template slot-scope="scope">
              <dict-tag :options="dict.type.sys_site_list" :value="scope.row.site" />
            </template> -->
          </el-table-column>
          <el-table-column label="所在日期" min-width="200" show-overflow-tooltip>
            <template slot-scope="scope">
              <!-- {{ scope.$index }} -->
              <div style="display: flex;">
                <!-- 开始时间 -->
                <div>
                  <span v-if="dataPayLogList.length - 1 == scope.$index">
                    {{ scope.row.startTime }}~
                  </span>
                  <span v-else>
                    {{ checkHistoryNode(scope.row, "jsfzr").commentList && checkHistoryNode(scope.row,
                      "jsfzr").commentList[0].time.substring(0,11) }} ~
                  </span>
                </div>
                <div>
                  <!-- 结束时间 -->
                  <span v-if="dataPayLogList[scope.$index - 1]">
                    {{ checkHistoryNode(dataPayLogList[scope.$index - 1], "jsfzr").commentList &&
                      checkHistoryNode(dataPayLogList[scope.$index - 1], "jsfzr").commentList[0].time.substring(0,11) }}
                  </span>
                  <span v-else>至今</span>
                </div>
              </div>


              <!-- {{ scope.row.startTime }}~{{ scope.row.endTime ? scope.row.endTime : '至今' }} -->
            </template>
          </el-table-column>
        </el-table-column>

      </el-table>
      <pagination v-show="dataPayLogList.length" :total="totalLog" :page.sync="logParams.pageNum"
        :limit.sync="logParams.pageSize" @pagination="getListLog" />
    </el-dialog>
  </div>
</template>

<script>
import { listDevice, delDevice, deviceAudit, updategdevice } from "@/api/device/device.js";
import { deptTreeSelect } from "@/api/system/user.js";
import printStyle from "@/utils/print.js";
import {
  listwanderHistory,
} from "@/api/device/wanderHistory.js";
export default {
  name: "Register",
  dicts: ["sys_manufacturer_list", "sys_site_list", "sys_trace_method"],

  data() {
    return {
      openAudit: false,
      dialogFormVisible: false,
      form: {

      },
      formData: {
        managerAudit: "1",
      },
      rules: {
        managerCause: [
          {
            required: true,
            message: "拒绝原因不能为空",
            trigger: "blur",
          },
        ],
      },
      showCode: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      dataList: [],
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      deptOptions: [],
      // 查询参数
      queryParams: {
        deptId: [],
        deviceCode: undefined,
        pageNum: 1,
        pageSize: 10,
        title: undefined,
        operUserId: undefined,
        licenseNum: undefined,
        checkDate: null,
      },
      // 日期范围
      dateRange: [],

      userList: [],
      deptOptions: [],
      currentInfo: {},
      textUrl: "",
      infos: [], //勾选的数据
      printList: [],
      dataPayLogList: [],
      logParams: {
        pageNum: 1,
        pageSize: 10,
        id: undefined,
        from: 1
      },
      titleLog: "流转记录",
      openLog: false,
      loadingLog: false,
      totalLog: 0,
      print: {
        id: 'printArea',
        popTitle: '打印', // 打印配置页上方标题
        extraHead: '', //最上方的头部文字，附加在head标签上的额外标签,使用逗号分隔
        preview: false, // 是否启动预览模式，默认是false（开启预览模式，可以先预览后打印）
        previewTitle: '', // 打印预览的标题（开启预览模式后出现）,
        previewPrintBtnLabel: '', // 打印预览的标题的下方按钮文本，点击可进入打印（开启预览模式后出现）
        zIndex: '', // 预览的窗口的z-index，默认是 20002（此值要高一些，这涉及到预览模式是否显示在最上面）   
        url: '',
        standard: '',
        extraCss: '',
      },
      printItem: {},
    };
  },
  created() {
    const str = sessionStorage.getItem('queryParams');
    if (str) {
      this.queryParams = JSON.parse(str);
      if (this.queryParams.startEndDate) {
        this.dateRange.push(this.queryParams.startEndDate, this.queryParams.endEndDate)
      }
      setTimeout(() => {
        sessionStorage.removeItem('queryParams');
      }, 500)
    }
    this.getList();
    this.getDeptTree();
  },
  methods: {
    lableRender(e) {
      return (
        <el-row style={{ textAlign: 'center' }} type="flex" justify="space-around">
          <el-col span='8'>设备编号：{this.dataPayLogList[0] && this.dataPayLogList[0].deviceCode}</el-col>
          <el-col span='8'>设备名称：{this.dataPayLogList[0] && this.dataPayLogList[0].deviceName}</el-col>
          <el-col span='8'>设备型号：{this.dataPayLogList[0] && this.dataPayLogList[0].spec}</el-col>
        </el-row>
      );
    },
    /* 设备流转记录 */
    handleRecord(e) {
      this.logParams.deviceId = e.deviceId
      this.openLog = true
      this.getListLog()
    },
    getListLog() {
      this.loadingLog = true;
      listwanderHistory(this.logParams).then((response) => {
        this.dataPayLogList = response.rows;
        this.loadingLog = false;
      });
    },
    handleprintArea(e) {
      console.log(e);
      this.printItem = e
      this.textUrl =
        process.env.VUE_APP_CODE_API + "deviceDetail?id=" + e.deviceId;
      console.log(this.textUrl);
      this.$print({
        // 指定要打印的组件名称
        printable: 'printArea',
        id: 'printArea',
        popTitle: "标准物质入库标签", // 打印的标题
        extraCss: "", // 打印可引入外部的一个 css 文件
        extraHead: "", // 打印头部文字
        filter: ['.no-print'],
        // 可选参数，可以设置打印前回调函数和打印后回调函数
        beforePrint: () => { },
        afterPrint: () => { }
      }, 500);
    },
    /** 上传按钮操作 */
    handleUpload(row) {
      this.dialogFormVisible = true
      this.form = row
      // const configId = row.deviceCheckId || this.ids;
      // this.$router.push("./addCheck?isEdit=true&id=" + configId);
    },
    submit() {
      updategdevice(this.form).then((response) => {
        this.$modal.msgSuccess("修改成功");
        this.resetForm();
        this.dialogFormVisible = false
      });
    },
    printBox() {
      //infos  勾选的数据 如果有勾选就打印勾选。
      if (this.infos.length) {
        this.printList = this.infos;
      } else {
        //反之打印当前整个列表
        this.printList = this.dataList;
      }
      setTimeout(() => {
        document.title = "设备情况登记表 STET/B/20-1";

        this.$print({
          printable: "printBox", //打印区域id
          type: "html", //打印类型是html
          scanStyles: false,
          targetStyles: ["*"],
          style: this.workStyle(),
          onPrintDialogClose: () => {
            document.title = process.env.VUE_APP_TITLE;
          },
        });
      }, 500);
    },
    // 可以自定义样式  printStyle 是公共样式 切勿私自修改
    workStyle() {
      return `${printStyle}
        table,
        table tr th,
        table tr td {
          padding: 4px;
        }
        .desc{
        text-align: left; font-size: 12px; margin-top: 10px
      }
            .df {
                display: flex;
              }
      `;
    },
    handleCode(e) {
      this.textUrl =
        process.env.VUE_APP_CODE_API + "?id=" + e.deviceId;
      this.showCode = true;
    },
    handleBus(row) {
      console.log(row.isStartPiid);
      if (row.isStartPiid !== 2) return;
      const pathList = [
        {
          path: "/register/process/detail/",
          id: "deviceId",
          name: "设备情况登记",
        },
        {
          path: "/deviceConfirm/process/detail/",
          id: "deviceConfirmId",
          name: "设备(工具)符合性确认",
        },
        {
          path: "/deviceStatus/process/detail/",
          id: "deviceStatusId",
          name: "维修",
        },
        {
          path: "/deviceStatus/process/detail/",
          id: "deviceStatusId",
          name: "停用",
        },
        {
          path: "/deviceStatus/process/detail/",
          id: "deviceStatusId",
          name: "报废",
        },
        {
          path: "/deviceStatus/process/detail/",
          id: "deviceStatusId",
          name: "恢复",
        },
        {
          path: "/checkAsk/process/detail/",
          id: "deviceCheckAskId",
          name: "仪器设备计量检定要求",
        },
        {
          path: "/checkAsk/process/detail/",
          id: "deviceCheckAskId",
          name: "上传外部检测证书(维修) ",
        },
        {
          path: "/checkAsk/process/detail/",
          id: "deviceCheckAskId",
          name: "上传外部检测证书(检定) ",
        },
        {
          path: "/resultConfirm/process/detail/",
          id: "deviceResultConfirmId",
          name: "设备校准结果符合性确认 ",
        },

        // 待办业务 - -1-无 0-设备情况登记 1-设备(工具)符合性确认 2-维修 3-停用 4-报废 5-恢复
        // 6-仪器设备计量检定要求 7-上传外部检测证书(维修) 8-上传外部检测证书(检定) 9-设备校准结果符合性确认
      ];
      let pathInfo = pathList[row.busStatus];
      this.$router.push({
        path: pathInfo.path + row.piid,
        query: {
          definitionId: null,
          deployId: null,
          taskId: null,
          finished: false,
          id: row.busId,
        },
      });
    },
    handleExport() {
      this.download(
        "system/device/export",
        {
          ...this.queryParams,
          deptId: this.queryParams.deptId.slice(-1)[0]
        },
        `设备登记情况记录表_${this.parseTime(
          new Date().getTime(),
          "{y}-{m}-{d}"
        )}.xlsx`
      );
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.deviceId);
      this.infos = selection;
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },

    /** 登记按钮操作 */
    handleUpdate(row) {
      const configId = row.deviceId || this.ids;
      let e = this.dataList.find((i) => i.deviceId == configId);
      if (e.isComplete == 1) {
        this.$message.warning("信息补充完整，不允许修改");
        return;
      }
      this.$router.push("./addRegister?isReg=true&id=" + configId);
    },
    handleUpdate2(row, isAdminOpt) {
      sessionStorage.setItem('queryParams', JSON.stringify(this.queryParams));
      const configId = row.deviceId || this.ids;
      this.$router.push("./addRegister?isEdit=true&id=" + configId + '&isAdminOpt=' + isAdminOpt);
    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then((response) => {
        this.deptOptions = response.data;
      });
    },
    checkName(e) {
      console.log(e, "name");
    },
    handleDetail(row) {
      sessionStorage.setItem('queryParams', JSON.stringify(this.queryParams));
      this.$router.push("./addRegister?isInfo=true&id=" + row.deviceId);
      // this.$router.push({
      //   path: "/register/process/detail/" + row.piid,
      //   query: {
      //     definitionId: null,
      //     deployId: null,
      //     taskId: null,
      //     finished: false,
      //     id: row.deviceId,
      //   },
      // });
    },
    handleAudit(row) {
      this.formData = {
        managerAudit: "1",
        deviceId: row.deviceId,
      };
      this.openAudit = true;
    },
    submitForm: function () {
      this.$refs["elForm"].validate((valid) => {
        if (valid) {
          let query = JSON.parse(JSON.stringify(this.formData));
          deviceAudit(query).then((response) => {
            this.$modal.msgSuccess("审核成功");
            this.openAudit = false;
            this.getList();
          });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const configId = row.deviceId || this.ids;

      this.$modal
        .confirm('是否确认删除ID为"' + configId + '"的数据项？')
        .then(function () {
          return delDevice(configId);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    handleAdd() {
      this.$router.push("./addRegister");
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      listDevice({
        ...this.addDateRangeTime(
          this.queryParams,
          this.dateRange,
          "startEndDate",
          "endEndDate"
        ),
        deptId: this.queryParams.deptId.slice(-1)[0],
      }).then((response) => {
        this.dataList = response.rows;
        console.log(this.dataList);
        // this.dataList.forEach(item => {
        //     this.$set(item,'isComplete',item.isComplete)
        // });
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
<style>
@media print {
  .noprint {
    display: block !important;
  }
}

@page {
  size: auto;
  margin: 0mm;
}

.procedure {
  word-wrap: break-word;
}
</style>
<style lang="scss" scoped>
.noprint {
  display: none;
}

#printArea {
  width: 500px;
  height: 300px;
  padding: 10px;

  // margin: 10px auto;
  .printWait {
    padding: 5px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;

    // border: 1px solid #333;
    .item {
      margin-bottom: 2px;
      font-size: 12px;
    }
  }
}

.fw {
  font-weight: bold;
}

.tac {
  text-align: center;
}

.br {
  border: 2px solid #000;
}

::v-deep .el-dialog__body {
  img {
    width: 100%;
  }
}
</style>
